package org.wwb.antbox.center.web.controller.sys.menu;

import org.ant.commons.models.model.BaseIdModel;
import org.ant.commons.models.result.BaseEditResult;
import org.ant.commons.models.result.BasePageResult;
import org.ant.commons.models.result.BaseResult;
import org.springframework.web.bind.annotation.*;
import org.wwb.antbox.center.web.Router;
import org.wwb.antbox.user.iservice.ServiceUserTool;
import org.wwb.antbox.user.model.menu.model.*;
import org.wwb.antbox.user.model.menu.view.SysMenuPageView;
import org.wwb.antbox.user.model.menu.view.SysMenuTreeView;
import org.wwb.antbox.user.model.menu.view.SysMenuTreeViewNew;
import org.wwb.antbox.user.model.system.entity.SysSystem;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @Author Bond
 * @Date: 2019/9/22 12:39
 * @Description: 系统菜单控制器
 */
@RestController
public class SysMenuController {
    /**
     * 获取系统菜单分页列表
     * @param sysMenuTreeGridModel
     * @return BasePageResult<SysMenuPageView>
     */
    @PostMapping(value = Router.SysMenu.GET_SYS_MENU_TREE_GRID)
    public BasePageResult<SysMenuPageView> getSysMenuTreeGrid(@RequestBody @Valid SysMenuTreeGridModel sysMenuTreeGridModel){
        return ServiceUserTool.sysMenuService().getSysMenuTreeGrid(sysMenuTreeGridModel);
    }

    /**
     * 获取功能菜单树数据
     * @param sysMenuTreeModel
     * @return BaseResult<List<SysMenuTreeView>>
     */
    @PostMapping(value = Router.SysMenu.GET_SYS_MENU_TREE)
    public BaseResult<List<SysMenuTreeView>> getSysMenuTree(@RequestBody @Valid SysMenuTreeModel sysMenuTreeModel){
        return ServiceUserTool.sysMenuService().getSysMenuTree(sysMenuTreeModel);
    }

    /**
     * 添加系统菜单
     * @param sysMenuAddModel
     * @return BasePageResult<Integer>
     */
    @PostMapping(value = Router.SysMenu.SAVE_SYS_MENU)
    public BaseResult<Integer> saveSysMenu(@RequestBody @Valid SysMenuAddModel sysMenuAddModel){
        return ServiceUserTool.sysMenuService().saveSysMenu(sysMenuAddModel);
    }

    /**
     * 删除系统菜单
     * @param sysMenuDelModel
     * @return BaseResult<Integer>
     */
    @PostMapping(value = Router.SysMenu.DEL_SYS_MENU)
    public BaseResult<Integer> delSysMenu(@RequestBody @Valid SysMenuDelModel sysMenuDelModel){
        return ServiceUserTool.sysMenuService().delSysMenu(sysMenuDelModel);
    }

    /**
     * 跳转修改系统菜单
     * @param id id
     * @return BaseEditResult
     */
    @GetMapping(value = Router.SysMenu.DO_EDIT_SYS_MENU)
    public BaseEditResult doEditSysMenu(@RequestParam("id") Integer id){
        return ServiceUserTool.sysMenuService().doEditSysMenu(new BaseIdModel(id));
    }

    /**
     * 修改系统菜单
     * @param sysMenuEditModel
     * @return BaseResult<Integer>
     */
    @PostMapping(value = Router.SysMenu.EDIT_SYS_MENU)
    public BaseResult<Integer> editSysMenu(@RequestBody @Valid SysMenuEditModel sysMenuEditModel){
        return ServiceUserTool.sysMenuService().editSysMenu(sysMenuEditModel);
    }

    /**
     * 获取菜单树4添加角色  添加角色时用
     * Map<String,List<SysMenuTreeView>>
     * key: 系统编号
     * value：菜单树集合
     * @return BaseResult<Map<String,List<SysMenuTreeView>>>
     */
    @GetMapping(value = Router.SysMenu.GET_SYS_MENU_TREE4_ADD_ROLE)
    public BaseResult<Map<String, List<SysMenuTreeViewNew>>> getSysMenuTree4AddRole(){
        List<SysSystem> sysSystemList = ServiceUserTool.sysSystemService().getSysSystemList().getModel();
        return ServiceUserTool.sysMenuService().getSysMenuTree4AddRole(sysSystemList);
    }
}
